#ifndef GROWBUF_H
#define GROWBUF_H

/**
* A dynamic string class that grows as needed
*/
class GrowBuf
{
	public:
		GrowBuf();
		~GrowBuf();

		/**
		* Append a character to the string
		* 
		* @param ch character to be added
		*
		* @return true of character added
		*/
		bool8 add(char  ch);

		/**
		* Append a string to the string
		* 
		* @param str string to be appended
		*
		* @return true of string appended
		*/
		bool8 add(char* str);

		/**
		* Append a string to the string
		* 
		* @param str	string to be appended
		* @param amount number of characters to be appended
		*
		* @return true of string appended
		*/
		bool8 add(char* str, int32 amount);

		/**
		* Clears the string
		*/
		void clear();

		/**
		* Returns a null termiated string
		*
		* @return the null termiated string
		*/
		char* getBuf();
		
		/**
		* Returns the length of the string not including the terminating null
		*
		* @return the length of the string not including the terminating null
		*/
		int32 getSize();

	private:
		/**
		* Grows the string
		*
		* @param size	amount to grow string
		* 
		* @return true if the string was grown
		*/
		bool8 ensure(int32 size);

	private:
		static char empty;	/**< an empty string */

	protected:
		int32 maxSize;		/**< the maximum length of the current string	*/
		int32 curSize;		/**< the current string length					*/
		char* buf;			/**< the current string							*/
};

inline char*
GrowBuf::getBuf()
{
	ASSERT(empty == '\0');
	return buf ? buf : &empty;
}

inline int32
GrowBuf::getSize()
{
	return curSize;
}

#endif
